package com.hfjyz.judge.judge.action;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

import com.hfjyz.base.constant.BaseConstant;
import com.hfjyz.base.exception.BaseException;
import com.hfjyz.judge.judge.service.JudgeService;
import com.hfjyz.system.user.bean.UserBean;
import com.opensymphony.xwork2.ActionSupport;

public class JudgeUploadAction extends ActionSupport {

    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 6802363970732485121L;
    private static final Log SYS_LOG = LogFactory.getLog(BaseConstant.SYS_LOG);
    private File photo = null;
    private String fileFileName = null;
    private String fileFileContentType = null;
    private String idNo = null;
    private JudgeService service = null;

    private Map<String, Object> map = new HashMap<String, Object>();

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    public File getPhoto() {
        return photo;
    }

    public void setPhoto(File photo) {
        this.photo = photo;
    }

    public String getFileFileName() {
        return fileFileName;
    }

    public void setFileFileName(String fileFileName) {
        this.fileFileName = fileFileName;
    }

    public String getFileFileContentType() {
        return fileFileContentType;
    }

    public void setFileFileContentType(String fileFileContentType) {
        this.fileFileContentType = fileFileContentType;
    }

    public String getIdNo() {
        return idNo;
    }

    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }

    public JudgeService getService() {
        return service;
    }

    public void setService(JudgeService service) {
        this.service = service;
    }

    public String execute() {
        HttpSession session = ServletActionContext.getRequest().getSession();
        UserBean user = (UserBean) session.getAttribute(BaseConstant.SESSION_USER_INFO_KEY);

        map = new HashMap<String, Object>();
        try {
            service.uploadPhoto(idNo, photo, user.getId());
        } catch (BaseException e) {
            map.put("errorMsg", e.getMessage());
        } catch (Exception e) {
            SYS_LOG.error("发生未知错误！", e);
            map.put("errorMsg", "发生未知错误，请联系管理员！");
        }
        return SUCCESS;
    }
}
